﻿	<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
	<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
	<%@ page import="com.cxx.purchasecharge.component.utils.ComponentConstants"%>
	<%@ page import="com.cxx.purchasecharge.component.bean.TimeFrame"%>
	
	<script type="text/javascript">
		var onOrderProfitSelectStartDate = function (date) 
		{
			$('#toolbar-outorder-profit #advanceSearchSpan #timeFrame').combobox('setValue', 'CUSTOMIZE');
		}
		var onOrderProfitSelectTimeFrame = function(record) 
		{
			setInitialOrderProfitTimeFrame(record.value);
		}
		var pageInfo = {page: 1, rows: 10};
		var onSearchOrderProfitByAdvance = function () 
		{
			var startDate = $('#toolbar-outorder-profit #advanceSearchSpan #startDate').combo('getValue');
			var endDate = $('#toolbar-outorder-profit #advanceSearchSpan #endDate').combo('getValue');
			var customerId = $('#toolbar-outorder-profit #advanceSearchSpan #customerId').combo('getValue');
			if((startDate != '' && endDate == '') || (startDate == '' && endDate != '')) 
			{
				$.messager.alert('警告','开始时间和结束时间必须同时填!','warning');
				return;
			}
			if(startDate == '' && endDate == '' && customerId == '') 
			{
				$.messager.alert('警告','请填写查询条件!','warning');
				return;
			}
			loadGridData ('#dg-outorder-profit', '<c:url value='/outOrder/getOrderProfitDetail.html' />', {page:pageInfo.page, rows:pageInfo.rows, startDate:startDate, endDate:endDate, customerId:customerId});
		}
		var defaultOrderProfitTimeFrame = 'RECENT_THIRTY_DAYS';
		var onBeforeLoadOrderProfit = function (param) 
		{
			pageInfo = param;
			var startDate = $('#toolbar-outorder-profit #advanceSearchSpan #startDate').combo('getValue');
			var endDate = $('#toolbar-outorder-profit #advanceSearchSpan #endDate').combo('getValue');
			var customerId = $('#toolbar-outorder-profit #advanceSearchSpan #customerId').combo('getValue');
			if(customerId == undefined) 
			{
				customerId = '';
			}
			if(startDate == '' && endDate == '' && customerId == '') 
			{
				var timeFrame = $('#toolbar-outorder-profit #advanceSearchSpan #timeFrame').combo('getValue');
				setInitialOrderProfitTimeFrame(timeFrame);
				
				startDate = $('#toolbar-outorder-profit #advanceSearchSpan #startDate').combo('getValue');
				endDate = $('#toolbar-outorder-profit #advanceSearchSpan #endDate').combo('getValue');
			}
			
			$('#dg-outorder-profit').datagrid('options').url = "<c:url value='/outOrder/getOrderProfitDetail.html' />?startDate="+startDate+"&endDate="+endDate+"&customerId="+customerId;
			return true;
		}
		var setInitialOrderProfitTimeFrame = function(timeFrame) 
		{
			var startDate = generateStartDate(timeFrame);
			var endDate = new Date().format("yyyy-MM-dd");
			$('#toolbar-outorder-profit #advanceSearchSpan #startDate').datebox('setValue', startDate);
			$('#toolbar-outorder-profit #advanceSearchSpan #endDate').datebox('setValue', endDate);
		}
	</script>
	
	<table id="dg-outorder-profit" title="订单利润统计" class="easyui-datagrid"
		toolbar="#toolbar-outorder-profit" pagination="true" rownumbers="true" showFooter="true" 
		singleSelect="true" checkOnSelect="true" selectOnCheck="false" fit="true"  
		fitColumns="true" sortName="<%=ComponentConstants.CREATE_TIME %>" sortOrder="desc" 
		data-options="onBeforeLoad:onBeforeLoadOrderProfit">
		<thead>
			<tr>
				<th data-options="field:'id'"><spring:message code="order.id" /></th>
				<th field="<%=ComponentConstants.CUSTOMER_NAME %>" width="60" sortable="true" data-options="formatter:customerNameFormatter"><spring:message code="order.customer" /></th>
				<th field="<%=ComponentConstants.RECEIVABLE_MONEY %>" width="40" sortable="true"><spring:message code="order.dealMoney" /></th>
				<th field="<%=ComponentConstants.PROFIT_MONEY %>" width="40" sortable="true"><spring:message code="order.profit" /></th>
				<th field="<%=ComponentConstants.CREATE_TIME %>" width="80" sortable="true"><spring:message code="order.createDate" /></th>
				<th field="signUserId" width="40" sortable="true"><spring:message code="order.signUserId" /></th>
				<th field="operateUserId" width="40" sortable="true">操作员</th>
				<th field="typeCode" width="30" sortable="true" data-options="formatter:orderTypeFormatter, styler:cellStyler_userRole, align:'center'">类型</th>
				<th field="statusCode" width="30" data-options="formatter:orderStatusFormatter, align:'center'"><spring:message code="order.statusCode" /></th>
			</tr>
		</thead>
	</table>
	
	<div id="toolbar-outorder-profit" style="padding:5px;height:auto">
		<div>
			<span id="advanceSearchSpan" style="width: 100%; display: inline-block;">
				<form id="outOrderSearchForm" action="">
	            	时间: <input id="startDate" name="startDate" class="easyui-datebox" style="width:100px" 
					editable="false" title="开始时间" data-options="onSelect: onOrderProfitSelectStartDate">
	            	- <input id="endDate" name="endDate" class="easyui-datebox" style="width:100px" 
					editable="false" title="结束时间" data-options="onSelect: onOrderProfitSelectStartDate">&nbsp;
					<select id="timeFrame" name="timeFrame" class="easyui-combobox" style="width:80px" panelHeight="auto" editable="false" data-options="onSelect: onOrderProfitSelectTimeFrame">
						<option value="CUSTOMIZE"><%=TimeFrame.CUSTOMIZE.getText () %></option>
						<option value="TODAY"><%=TimeFrame.TODAY.getText () %></option>
						<option value="RECENT_THREE_DAYS"><%=TimeFrame.RECENT_THREE_DAYS.getText () %></option>
						<option value="RECENT_SEVEN_DAYS"><%=TimeFrame.RECENT_SEVEN_DAYS.getText () %></option>
						<option value="RECENT_FIFTEEN_DAYS"><%=TimeFrame.RECENT_FIFTEEN_DAYS.getText () %></option>
						<option value="RECENT_THIRTY_DAYS" selected="selected"><%=TimeFrame.RECENT_THIRTY_DAYS.getText () %></option>
						<option value="CURRENT_MONTH"><%=TimeFrame.CURRENT_MONTH.getText () %></option>
					</select>
	            	&nbsp;
	            	客户: 
	           		<input id="customerId" name="customerId" class="easyui-combobox" style="width:100px" data-options="valueField:'id',
												textField:'shortName',
												url:'',
												mode:'local',
												filter:comboboxFilter,
												onShowPanel:onClickCustomerCombox" />
					<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" title="查询出库单" onclick="onSearchOrderProfitByAdvance()">查询</a>
				</form>
	        </span>
        </div>
	</div>
	
